package com.yfwl.ex2uiex1;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.TableLayout;

public class HomeActivity extends Activity implements ActionBar.TabListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        if (savedInstanceState == null) {
            getFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
        ActionBar mActionBar = getActionBar();
        mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        ActionBar.Tab tabCreateNote = mActionBar.newTab();
        tabCreateNote.setText("新建笔记");
        tabCreateNote.setTabListener(this);
        mActionBar.addTab(tabCreateNote);

        ActionBar.Tab tabAllNotes = mActionBar.newTab();
        tabAllNotes.setText("全部笔记");
        tabAllNotes.setTabListener(this);
        mActionBar.addTab(tabAllNotes);

        ActionBar.Tab tabClassification = mActionBar.newTab();
        tabClassification.setText("分类");
        tabClassification.setTabListener(this);
        mActionBar.addTab(tabClassification);

        ActionBar.Tab tabPhotoTransit = mActionBar.newTab();
        tabPhotoTransit.setText("照片中转站");
        tabPhotoTransit.setTabListener(this);
        mActionBar.addTab(tabPhotoTransit);

        ActionBar.Tab tabMore = mActionBar.newTab();
        tabMore.setText("更多");
        tabMore.setTabListener(this);
        mActionBar.addTab(tabMore);


    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.home, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        switch (item.getItemId()) {
            case R.id.action_settings:
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

    }

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) {

    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_home, container, false);
            return rootView;
        }
    }

}
